package algorithm.dynamicProgramming.leetcode;
//746. 使用最小花费爬楼梯
public class MinCostClimbingStairs {
    public static void main(String[] args) {

        int[] data = {10,15};
        System.out.println(minCostClimbingStairs2(data));
    }

    public static int minCostClimbingStairs(int[] cost) {
            int n = cost.length;
            int[] f = new int[n+1];
            f[0]= 0;
            f[1] = 0;
            for (int i=2;i<=n;i++){
                f[i] = Math.min(f[i-1]+cost[i-1],f[i-2]+cost[i-2]);
            }
            return f[n];

    }

    public static int minCostClimbingStairs2(int[] cost) {
        int n = cost.length;
        int[] f = new int[n+1];
        f[0]= cost[0];
        f[1] = cost[1];
        for (int i =2;i<n;i++){
            f[i] = Math.min(f[i-1],f[i-2]+cost[i-1]);
        }

        return f[n];
    }
}
